<?php
##############################################
#
#   奖品
# @ Time : 2017-1-30 - 下午11:24:18
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Home\Model;

class PrizeModel extends IndexBaseModel{
	/*奖品表  */
	protected $tableName = 'prize';

	//获取该规则下的奖品
	public function getPrizeList(){
	    //取8个奖品
         return $result = $this -> where("surplus_num > 0 and status = 1") ->limit(8) ->order('p_id desc')-> select();
         //var_dump($result);
         //echo $this->getLastSql();
    
    }


    //减去一个奖品
    public function reduceOnePrize($p_id){
    	return $this -> where("p_id = $p_id") -> setDec('surplus_num');
    }

    //获取奖品数据
    public function getPrize($p_id){
    	return $this -> where("p_id = $p_id") -> find();
    }

    //减去一次抽奖数
    public function reduceUserNum($user_id){
    	$model = M();
    	return $model -> table('mt_userinfo') -> where("id = $user_id") -> setDec('luckdraw_num');
    }


    //获取用户的可抽奖数
    public function getLuckdrawNum($user_id){
    	$model = M();
    	return $model -> table('mt_users') -> where("id = $user_id") -> getField('luckdraw_num');
    }

}
